package com.graduation.project.controller.system;

import com.graduation.project.entity.dto.unit.ListUnitDTO;
import com.graduation.project.entity.dto.UpdateStatusDTO;
import com.graduation.project.entity.dto.unit.SaveOrUpdateUnitDTO;
import com.graduation.project.service.system.UnitManagementService;
import com.graduation.project.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/unit_management")
public class UnitManagementController {

    @Autowired
    private UnitManagementService unitManagementService;

    /**
     * （条件）查询单位列表数据
     * @param input 查询单位列表输入类
     * @return ResultUtil
     */
    @PostMapping("/post/listUnitByCondition")
    public ResultUtil<?> listUnitByCondition(@RequestBody ListUnitDTO input) {
        return unitManagementService.listUnitByCondition(input);
    }

    /**
     * 获取弹窗父级单位下拉数据
     * @return ResultUtil
     */
    @GetMapping("/get/listParentUnit")
    public ResultUtil<?> listParentUnit() {
        return unitManagementService.listParentUnit();
    }

    /**
     * 新增单位
     * @param input 新增/修改输入类
     * @return ResultUtil
     */
    @PostMapping("/post/addUnit")
    public ResultUtil<?> addUnit(@RequestBody SaveOrUpdateUnitDTO input) {
        return unitManagementService.addUnit(input);
    }

    /**
     * 修改单位
     * @param input 新增/修改输入类
     * @return ResultUtil
     */
    @PutMapping("/put/updateUnit")
    public ResultUtil<?> updateUnit(@RequestBody SaveOrUpdateUnitDTO input) {
        return unitManagementService.updateUnit(input);
    }

    /**
     * 删除单位及其子项
     * @param id 选中数据id
     * @return ResultUtil
     */
    @DeleteMapping("/delete/deleteUnit")
    public ResultUtil<?> deleteUnit(@RequestParam("id") Long id) {
        return unitManagementService.deleteUnit(id);
    }

    /**
     * 修改单位状态
     * @param input 修改状态输入类
     * @return ResultUtil
     */
    @PutMapping("/put/updateUnitStatusById")
    public ResultUtil<?> updateUnitStatusById(@RequestBody UpdateStatusDTO input) {
        return unitManagementService.updateUnitStatusById(input);
    }
}
